package org.example;

import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;

/**
 * 习题类的单元测试类（JUnit5）
 */
class ExercisePaperTest {

    @Test
    void testCalculateAccuracy() {
        // 1. 创建习题并添加3道算式
        ExercisePaper paper = new ExercisePaper("测试习题");
        ArithmeticExpression exp1 = new ArithmeticExpression(2, 3, '+');
        ArithmeticExpression exp2 = new ArithmeticExpression(5, 2, '-');
        ArithmeticExpression exp3 = new ArithmeticExpression(4, 5, '*');
        paper.addExpression(exp1);
        paper.addExpression(exp2);
        paper.addExpression(exp3);

        // 2. 模拟用户答案（对2道，错1道）
        Map<ArithmeticExpression, Double> answers = new HashMap<>();
        answers.put(exp1, 5.0); // 对
        answers.put(exp2, 2.0); // 错
        answers.put(exp3, 20.0); // 对

        // 3. 验证正确率（2/3 ≈ 0.67）
        assertEquals(0.67, paper.calculateAccuracy(answers), 0.01);
    }

    @Test
    void testAddExpression() {
        ExercisePaper paper = new ExercisePaper("测试习题");
        paper.addExpression(new ArithmeticExpression(2, 3, '+'));
        assertEquals(1, paper.getAllExpressions().size());
    }
}